﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AP.Framework.Infrastructure.Entities;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Database;

namespace AP.Framework.Infrastructure.Repositories
{
    public class DownloadRepository : Repository<cms_Download>, IDownload
    {
        protected override Func<cms_Download, object> DefaultOrderBy
        {
            get
            {
                return x => x.ID;
            }
        }

        public DownloadRepository(ApContext context) : base(context) { }

        public override void Add(cms_Download entity)
        {

            var exists = DefaultSet.Any();
            if (!exists)
            {
                base.Add(entity);
            }
        }

        public override cms_Download FindById(int id)
        {
            return (from entity in DefaultSet
                    where id == entity.ID
                    select entity).SingleOrDefault();
        }

        public override IEnumerable<cms_Download> FindById(params int[] ids)
        {
            return from entity in DefaultSet
                   where ids.Contains(entity.ID)
                   select entity;
        }
    }
}
